package com.tp03g03;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

public class ReminderService extends IntentService {
	private static final int NOTIF_ID = 1;

	public ReminderService() {
		super("ReminderService");
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		SharedPreferences settings = getSharedPreferences(
				Constantes.PREFS_NAME, 0);

		notificar(settings.getString("MensajeAlarma", "Organizador de asados"));
	}

	private void notificar(String texto) {
		NotificationManager mNM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

		Notification notification = new Notification(R.drawable.icon, texto,
				System.currentTimeMillis());

		PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
				new Intent(this, MainActivity.class), 0);

		notification.setLatestEventInfo(this, texto, texto, contentIntent);

		mNM.notify(1, notification);
	}
}
